import { Operate } from '@/enums'
import { useSetUrlSearchParam, useUrlQueryParam } from './useUrlQueryParam'

export const useDetailDrawer = () => {
  const [{ create }, setCreate] = useUrlQueryParam(['create'])
  const [{ id }, setId] = useUrlQueryParam(['id'])
  const setUrlParams = useSetUrlSearchParam()

  const onOpen = (id?: any) => {
    if (id) {
      // setId({ id })
      setUrlParams({ create: '', id })
    } else {
      setUrlParams({ create: true, id: '' })
      // setCreate({ create: true })
    }
  }
  const onClose = () => setUrlParams({ create: '', id: '' })
  return {
    create, 
    id,
    open: create === 'true' || Boolean(id),
    onOpen,
    onClose
  }
}
